home *** CD-ROM | disk | FTP | other *** search
/ PCNet 2006 April / PCnet 2006-06.4.iso / shareware / nmsetup.exe / WebServer / web / _folderutils.php < prev    next >
Encoding:
PHP Script  |  2006-05-01  |  29.9 KB  |  705 lines

  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////////
  3. // <!--Copyright (c) 2006 Pure Networks Inc.  All rights reserved.-->
  4. ////////////////////////////////////////////////////////////////////////////////
  5. //
  6. // Build: 3.0.6121.0 (Stable)
  7. // $Revision: #3 $
  8. //
  9. ///////////////////////////////////////////////////
  10. // Set up some shared variables with values
  11. ///////////////////////////////////////////////////
  12. $arSharePath = "";
  13. $arFiles = "";
  14. $bPagination = false;
  15. $bFolderUtilsIncluded = true;
  16.  
  17. ///////////////////////////////////////////////////
  18. // Function to get and validate the page number
  19. // Pages are assumed to start at 1, not 0
  20. ///////////////////////////////////////////////////
  21. function returnPageNumber($count, $ObjectsPerPage, $sgPage)
  22. {
  23.     $pageNumber = 0;
  24.     if (isset($sgPage))
  25.     {
  26.         $pageNumber = intval($sgPage);
  27.     }
  28.     if (($pageNumber < 1))
  29.     {
  30.         $pageNumber = 1;
  31.     }
  32.     else
  33.     {
  34.         // we have a page number and it's above page number 1, let's make sure we're not at too high a page
  35.         // if we are, we set the page number to be the max available page number
  36.         if (ceil($count/$ObjectsPerPage) < $pageNumber)
  37.         {
  38.             $pageNumber = ceil($count/$ObjectsPerPage);
  39.         }
  40.     }
  41.     return $pageNumber;
  42. }
  43.  
  44. ///////////////////////////////////////////////////
  45. // build pagination string 
  46. ///////////////////////////////////////////////////
  47. function returnPaginationString($count, $ObjectsPerPage, $iPaginationBuffer, $pageNumber)
  48. {
  49.     global $bPagination, $sShare, $sPath, $iMaxPage, $sNavPage, $sQuery;
  50.     $sPagination = "";
  51.     $sQuery = $_SERVER['PHP_SELF'];
  52.     
  53.     if (strpos($sQuery, "?") > 0)
  54.     {
  55.         if (strpos($sQuery, "page") > 0)
  56.         {
  57.             $sQsVarConcat   = "";
  58.         }
  59.         else
  60.         {
  61.             $sQsVarConcat   = "&";
  62.         }
  63.     }
  64.     else
  65.     {
  66.         $sQsVarConcat   = "?";
  67.     }
  68.     if ($count > $ObjectsPerPage)
  69.     {
  70.         $bPagination = true;
  71.         // What's the first page number link we display?
  72.         if (($pageNumber - $iPaginationBuffer) < 1)
  73.         {
  74.             $iMinPage = 1;
  75.         }
  76.         else
  77.         {
  78.             $iMinPage = ($pageNumber - $iPaginationBuffer);
  79.         }
  80.         
  81.         if (ceil($count/$ObjectsPerPage) < ($pageNumber + $iPaginationBuffer))
  82.         {
  83.             $iMaxPage = ceil($count/$ObjectsPerPage);
  84.         }
  85.         else
  86.         {
  87.             $iMaxPage = ($pageNumber + $iPaginationBuffer);
  88.         }
  89.         $sPagination  = "<br/><table class=\"PaginationTrayContain\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tr>";
  90.         $sPagination .= "<td class=\"PaginationTrayLeft\"><img src=\"/images/pixel.trans.gif\" height=\"1\" width=\"1\" alt=\"\"></td>";
  91.         $sPagination .= "<td class=\"PaginationTrayDefault\"><a href=\"";
  92.         $sPagination .= "javascript:gotoPage('" . $sQuery . "','1','" . ceil($count/$ObjectsPerPage) . "','" . $pageNumber . "','" . $sQsVarConcat . "');\">";
  93.         $sPagination .= "Page";
  94.         $sPagination .= "</a> ";
  95.     
  96.         // Do we put in the prev arrow?
  97.         if ($pageNumber > 1)
  98.         {
  99.             $sPagination .= " <span class=\"PaginationPrev\" title=\"Previous Page\"><a href=\"";
  100.             $sPagination .= $sQuery;
  101.             $sPagination .= $sQsVarConcat . 'page=' . ($pageNumber - 1);
  102.             $sPagination .=  "\">  </a></span>";
  103.         }
  104.         for($i=$iMinPage; $i<= $iMaxPage; $i++)
  105.         {
  106.             if ($i == $pageNumber)
  107.             {
  108.                 $sPagination .= "<span class=\"PaginationActive\">" . $i . " </span>" . " \r\n"; 
  109.             }
  110.             else
  111.             {
  112.                 $sPagination .= "<a href=\"" . $sQuery .  $sQsVarConcat . 'page=' . $i . "\" title=\"Go to page " . $i . "\">" . $i . "</a>  \r\n";
  113.             }
  114.         }
  115.         // Do we put in the next arrow?
  116.         if ($pageNumber < ceil($count/$ObjectsPerPage))
  117.         {
  118.             $sPagination .= "<span class=\"PaginationNext\" title=\"Next Page\"><a href=\"";
  119.             $sPagination .= $sQuery;
  120.             $sPagination .= $sQsVarConcat . 'page=' . ($pageNumber + 1);
  121.             $sPagination .=  "\">  </a></span>";
  122.         }
  123.         $sPagination .= "</td>";
  124.         $sPagination .= "<td class=\"PaginationTrayRight\"><img src=\"/images/pixel.trans.gif\" height=\"1\" width=\"1\" alt=\"\"></td>";
  125.         $sPagination .= "</tr></table> <!--Pagination-->";
  126.     }
  127.     return $sPagination;
  128. }
  129. ///////////////////////////////////////////////////
  130. // function that prints out the no content message
  131. ///////////////////////////////////////////////////
  132. function writeNoContentMessage($bUploadEnabled, $bReadOnly, $sAccessLevel)
  133. {
  134.     global $sProductNameInformal, $sParentProductNameInformal, $sNetworkName, $sNavPage, $bLoggedIn;
  135.     echo ("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" align=\"center\" class=\"WhiteTable\">");
  136.         echo ("<tr><td id=\"Top\"><img src=\"/images/pixel.trans.gif\" width=\"1\" height=\"1\" alt=\"\"/></td></tr>");
  137.         echo ("<tr>");
  138.             echo ("<td id=\"Mid\">");
  139.                 echo ("<div class=\"EmptyContianerImage\">");
  140.                     echo ("<div class=\"EmptyContianerText\">");
  141.                     switch ($sNavPage)
  142.                     {
  143.                         case "share":
  144.                             switch ($sAccessLevel)
  145.                             {
  146.                                 case 0:
  147.                                     echo ("There are no public folders available on this page.");
  148.                                     break;
  149.                                 case 1:
  150.                                 case 2:
  151.                                     echo ("There are no shared folders.");
  152.                                     break;
  153.                             }
  154.                             break;
  155.                         case "folders":
  156.                             switch ($sAccessLevel)
  157.                             {
  158.                                 case 0:
  159.                                 case 1:
  160.                                 case 2:
  161.                                     echo ("There are no files in this folder.");
  162.                                     break;
  163.                             }
  164.                             break;
  165.                     }
  166.                     echo ("</div>");
  167.                     echo ("<div class=\"EmptyContianerExplain\">");
  168.                     switch ($sNavPage)
  169.                     {
  170.                         case "share":
  171.                             if (!$bLoggedIn)
  172.                             {
  173.                                 echo ("If you are the owner of this page, click the Sign In button to see your private folders.");
  174.                             }
  175.                             else
  176.                             {
  177.                                 switch ($sAccessLevel)
  178.                                 {
  179.                                     case 0:
  180.                                         echo ("Click \"Shared Folders\" to see your private folders.");
  181.                                         break;
  182.                                     case 1:
  183.                                     case 2:
  184.                                         echo ("Click \"Public Home Page\" to see your public folders.");
  185.                                         break;
  186.                                 }
  187.                             }
  188.                             break;
  189.                         case "folders":
  190.                             switch ($sAccessLevel)
  191.                             {
  192.                                 case 0:
  193.                                     echo ("If you are a visitor, return to this site later or contact a member of this network for more information.");
  194.                                     break;
  195.                                 case 1:
  196.                                 case 2:
  197.                                     if ($bUploadEnabled & !$bReadOnly)
  198.                                     {
  199.                                         echo ("There are currently no files in this shared folder.  To add files, do one of the following depending on whether you are at home or away from home:");
  200.                                         echo ("<ul>");
  201.                                             echo ("<li>If you are at your computer, you can copy the files you want to share into this folder</li>");
  202.                                             echo ("<li>If you are away from home, you can upload individual files to this folder</li>");
  203.                                         echo ("</ul>");
  204.                                     }
  205.                                     else
  206.                                     {
  207.                                         echo ("There are currently no files in this shared folder.  To add files, copy the files you want to share into this folder.");
  208.                                     }
  209.                                     break;
  210.                             }
  211.                             break;
  212.                     }
  213.                     echo ("</div>");
  214.                 echo ("</div>");
  215.             echo ("</td>");
  216.         echo ("</tr>");
  217.         echo ("<tr><td id=\"Bot\"><img src=\"/images/pixel.trans.gif\" width=\"1\" height=\"1\" alt=\"\"/></td></tr>");
  218.     echo ("</table>");
  219. }
  220.  
  221. function printBreadcrumbs($sShare, $sUnc, $sFolderPath, $sContainer, $iBreadCrumbTruncateLength, $objCount, $ObjectsPerPage, $sgPage, $bPersistPageNumber)
  222. {
  223.     global $sNavPage, $ObjectsPerPage;
  224.     ///////////////////////////////////////////////////
  225.     // Generate the breadcrumb from the path
  226.     // Take the folder path \\kennt\NetMagic03, this is the root of the tree
  227.     // Breadcrumb should show
  228.     //      _My_Pictures
  229.     // After that, it should show the various folder depths
  230.     //     _My_Pictures \ _Folder1_ \ _Folder2_
  231.     // We will generate an array with two pieces of data per entry
  232.     //      breadcrumb[i]['name']
  233.     //      breadcrumb[i]['url']
  234.     ///////////////////////////////////////////////////
  235.  
  236.     ///////////////////////////////////////////////////
  237.     // This is the base url, it will return the user to the first page.
  238.     ///////////////////////////////////////////////////
  239.     $baseUrl = '/folderview/' . $sShare . "/" . urlEncodeString($sUnc);
  240.     $upFolderUrl = $baseUrl;
  241.     global $bLoggedIn;
  242.     if (strcmp($sFolderPath, $sUnc) == 0)
  243.     {
  244.         if (strlen($sContainer) < $iBreadCrumbTruncateLength)
  245.         {
  246.             $iRemainingChars = $iBreadCrumbTruncateLength - strlen($sContainer);
  247.         }
  248.         else
  249.         {
  250.             $iRemainingChars = 0;
  251.         }
  252.         
  253.         $breadcrumb[] = array("name" => truncate_string($sContainer, $iBreadCrumbTruncateLength, "...", "right", true), "url" => "", "title" => $sContainer);
  254.         $upFolderUrl = "/folders/";
  255.         if ($bLoggedIn)
  256.         {
  257.             $upFolderUrl .= "private";
  258.         }
  259.     }
  260.     else
  261.     {
  262.         $bTruncated = false; // Set truncation boolean to false as we have not yet truncated, but may along the way
  263.  
  264.         $remainingPath = substr($sFolderPath, strlen($sUnc) + 1); // skip past the beginning single slash
  265.         $pieces = explode('\\', $remainingPath);
  266.         $count = count($pieces);
  267.         $iRemainingChars = round($iBreadCrumbTruncateLength,0);
  268.  
  269.         ///////////////////////////////////////////////////
  270.         // stuff the breadcrumbs backwards (start at current folder and work backwards 
  271.         // towards the root shared folder) to be able to truncate on the left
  272.         // Add the last piece (current folder)
  273.         ///////////////////////////////////////////////////
  274.         if (strlen($pieces[$count-1]) > $iBreadCrumbTruncateLength)
  275.         {
  276.             ///////////////////////////////////////////////////
  277.             // our last piece is too long so we have to truncate already
  278.             ///////////////////////////////////////////////////
  279.             $breadcrumb[] = array("name" => truncate_string($pieces[$count-1], $iBreadCrumbTruncateLength, "...", "right", true), "url" => "", "title" => $pieces[$count-1]);
  280.             $bTruncated = true;
  281.         }
  282.         else
  283.         {
  284.             $breadcrumb[] = array("name" => $pieces[$count-1], "url" => "", "title" => $pieces[$count-1]);
  285.             $iRemainingChars = $iRemainingChars - strlen($pieces[$count-1]);
  286.         }
  287.  
  288.         if (!$bTruncated)
  289.         {
  290.             ///////////////////////////////////////////////////
  291.             // Add all items as urls except for the very last one (current folder)
  292.             ///////////////////////////////////////////////////
  293.             $i=($count)-2;
  294.             for ($i=($count)-2; $i>=0; $i--)
  295.             {
  296.                 $url = $baseUrl;
  297.                 $iRemainingChars = $iRemainingChars - strlen($pieces[$i]);
  298.                 ///////////////////////////////////////////////////
  299.                 // iterate through the items forwards (from the shared folder root to the current
  300.                 // folder) to create the path for the href for this item
  301.                 ///////////////////////////////////////////////////
  302.                 $j=0;
  303.                 for ($j=0;$j<=$i;$j++)
  304.                 {
  305.                     $url .= urlEncodeString("\\" . $pieces[$j]);
  306.                 }
  307.                 if ($i == ($count - 2 ))
  308.                 {
  309.                     $upFolderUrl = $url; // let's get the url for the parent folder setup here
  310.                     if ($bPersistPageNumber)
  311.                     {
  312.                         $upFolderUrl .= "?page=" . returnPageNumber($objCount, $ObjectsPerPage, $sgPage);
  313.                     }
  314.                 }
  315.                 if ($iRemainingChars >= 0)
  316.                 {
  317.                     $breadcrumb[] = array("name" => $pieces[$i], "url" => $url, "title" => $pieces[$i]);
  318.                 }
  319.                 else
  320.                 {
  321.                     $bTruncated = true;
  322.                     $breadcrumb[] = array("name" => truncate_string($pieces[$i], $iRemainingChars, "...", "right", true), "url" => $url, "title" => $pieces[$i]);
  323.                     ///////////////////////////////////////////////////
  324.                     // we've truncated, let's break out & adjust the remaining chars
  325.                     ///////////////////////////////////////////////////
  326.                     $iRemainingChars = $iRemainingChars - strlen($pieces[$i]);
  327.                     break;
  328.                 }
  329.             }
  330.         }
  331.  
  332.         ///////////////////////////////////////////////////
  333.         // Add the shared folder root of the path if there's room for it.
  334.         ///////////////////////////////////////////////////
  335.         if ($iRemainingChars > 0)
  336.         {
  337.             if ($bPersistPageNumber)
  338.             {
  339.                 $baseUrl .= "?page=" . returnPageNumber($objCount, $ObjectsPerPage, $sgPage);
  340.             }
  341.             if (strlen($sContainer) > $iRemainingChars)
  342.             {
  343.                 // not enough chars, let's truncate the root string...  
  344.                 $breadcrumb[] = array("name" => truncate_string($sContainer, $iRemainingChars, "...", "right", true), "url" => $baseUrl, "title" => $sContainer);
  345.             }
  346.             else
  347.             {
  348.                 $breadcrumb[] = array("name" => $sContainer, "url" => $baseUrl, "title" => $sContainer);
  349.             }
  350.         }
  351.     }
  352.  
  353.     ///////////////////////////////////////////////////
  354.     //got the info we need, let's start writing it...
  355.     ///////////////////////////////////////////////////
  356.     $iBreadcrumbChars = 0;
  357.     echo "<td class=\"ContentTableTM1\">";
  358.     echo "<span class=\"ParentUpFolder\"";
  359.     echo "onMouseOver=\"this.className='ParentUpFolderOver'\" onMouseOut=\"this.className='ParentUpFolder'\">";
  360.     echo "<a href=\"" . $upFolderUrl . "\" title=\"Go up to the next folder\">";
  361.     echo "<img src=\"/images/pixel.trans.gif\" alt=\"Go up to the next folder\" border=\"0\"/></a></span></td>";
  362.     echo "<td class=\"ContentTableTM2\">";
  363.     echo "<span class=\"Breadcrumbs\">";
  364.     if ($bLoggedIn)
  365.     {
  366.         echo ("<a href=\"/folders/private\" title=\"Go to shared folders.\">Home Page</a> \\ ");
  367.     }
  368.     else
  369.     {
  370.         echo ("<a href=\"/folders/public\" title=\"Go to shared folders.\">Home Page</a> \\ ");
  371.     }
  372.     
  373.     for ($k=(count($breadcrumb)); $k>0; $k--)
  374.     {
  375.         $crumb = $breadcrumb[$k-1];
  376.         if ($crumb['url'] != "")
  377.         {
  378.             print "<a href=\"" . htmlentities($crumb['url'])
  379.                 . "\" title=\"Go to " . htmlentities($crumb['title']) . "\">" 
  380.                 . str_replace(" ", " ",htmlentities($crumb['name'])) . "</a> \\ ";
  381.         }
  382.         else
  383.         {
  384.             print "<strong>" . str_replace(" ", " ",htmlentities($crumb['name'])) . "</strong>";
  385.         }
  386.     }
  387.     echo "</span></td>";
  388. } // -- breadcrumb function end --
  389.  
  390. function removeSharesFromArray($arArray, $iType)
  391. {
  392.     $iShareArrayCounter = 0;
  393.     try
  394.     {
  395.         foreach ($arArray as $share)
  396.         {
  397.             if ($share->AccessLevel != intval($iType))
  398.             {
  399.                 $arAvailableShares[$iShareArrayCounter] = $share;
  400.             }
  401.             $iShareArrayCounter++;
  402.         }
  403.         return $arAvailableShares;
  404.     }
  405.     catch (exception $ex)
  406.     {
  407.         return null;
  408.     }
  409. }
  410.  
  411. function createSessionFileArrays($sShare, $sPath, $sFolderPath, $nmSharedPlace, $bSamePageReset, $sgPage)
  412. {
  413.     global $arSharePath, $arFiles, $ObjectsPerPage, $bPlaylistLinkEnabled;
  414.     // Let's see if this folder is cached in the session, if it is, we use it to display
  415.     // folders and files, otherwise, we build one up, stick IT in the session, and then use it
  416.     // we compare an array that may be in the session with the current share/path to see if the
  417.     // folder in the session (if there is one) corresponds to teh current share/path.
  418.     // $arSharePath contains this info on the current share/path combination
  419.         // $arSharePath[0] = $sShare
  420.         // $arSharePath[1] = $sPath
  421.         // $arSharePath[2] = $sLastFileType - used to switch between UI styles for folders vs photos vs non photos
  422.         // $arSharePath[3] = $bSlideShowLinkEnabled - do we have any pictures at all here - if so we display the slideshow link
  423.         // $arSharePath[4] = $pageNumber - this is the page number we last requested
  424.     $bReadFolderFromFS = true;
  425.     if (isset($_SESSION['currentFolderInfo']))
  426.     {
  427.         $arSharePath = $_SESSION['currentFolderInfo'];
  428.         if ($arSharePath[0] == $sShare && $arSharePath[1] == $sPath)
  429.         {
  430.             // our session folder object is for the current share/path combination
  431.             if (returnPageNumber(count($_SESSION['currentFolderFiles']),$ObjectsPerPage, $sgPage) == $_SESSION['currentFolderInfo'][4])
  432.             {
  433.                 if ($bSamePageReset)
  434.                 {
  435.                     //we're asking for the same page, let's unset the cache
  436.                     unset($_SESSION['currentFolderInfo']);
  437.                     unset($_SESSION['currentFolderFiles']);
  438.                 }
  439.                 else
  440.                 {
  441.                     // we're just viewing images, let's not unset or readfrom fs
  442.                     $bReadFolderFromFS = false;
  443.                 }
  444.             }
  445.             else
  446.             {
  447.                 // no need to re-read from the FS
  448.                 $bReadFolderFromFS = false;
  449.                 //set new get request page number
  450.                 $_SESSION['currentFolderInfo'][4] = returnPageNumber(count($_SESSION['currentFolderFiles']),$ObjectsPerPage, $sgPage);
  451.                 $arSharePath = $_SESSION['currentFolderInfo'];
  452.                 $arFiles = $_SESSION['currentFolderFiles'];
  453.             }
  454.         }
  455.         else
  456.         {
  457.             // they differ, let's unset the session vars so they can get set properly below
  458.             unset($_SESSION['currentFolderInfo']);
  459.             unset($_SESSION['currentFolderFiles']);
  460.         }
  461.     }
  462.  
  463.     ///////////////////////////////////////////////////
  464.     // 1) we have no file info array in session, let's build it
  465.     // 2) the array we have in session does not match current
  466.     ///////////////////////////////////////////////////
  467.     if ($bReadFolderFromFS)
  468.     {
  469.         ///////////////////////////////////////////////////
  470.         // LEGENDS:
  471.         //  // (file types) legend
  472.         //      // we store the filetype in the [1] position of the various arrays so that we can split the displayed listings into sections
  473.         //      // 0 -- folder
  474.         //      // 1 -- picture
  475.         //      // 2 -- non picture file
  476.         //  // $arFolder folders, $arPhotos photo, and $arFiles non photo files arrays
  477.         //      // [$cFiles][0] - folder name/file name
  478.         //      // [$cFiles][1] - item type - see seperate legend above
  479.         // NOTE ON ABOVE ARRAYS:
  480.         // Since we want to display folders first, and then photos, and then files, we need to put these differing
  481.         // 'file' types into separate arrays until the end, where we slap the arrays together in the right order
  482.         // we don't know due to alpha order from teh filesystem where we'll find any of the mentioned item types,
  483.         // they'll be mixed
  484.         ///////////////////////////////////////////////////
  485.     
  486.         ///////////////////////////////////////////////////
  487.         // initalize some variables
  488.         ///////////////////////////////////////////////////
  489.         $arSharePath[0]             =   $sShare; // share info to compare to session based array on future visits
  490.         $arSharePath[1]             =   $sPath; // path info to compare to session based array on future visits
  491.         $cFiles                     =   0; // keeps count of which array element to define the information in
  492.         $arFiles                    =   null; // array for all files - we use this at the end
  493.         $arFilesPhotos              =   null; // array for photo files
  494.         $arFilesFiles               =   null; // array for non photo files
  495.         $arFolder                   =   null; // array for folders
  496.         $bSlideShowLinkEnabled      =   false;  // we won't show this unless we need to
  497.     
  498.         ///////////////////////////////////////////////////
  499.         // let's open up the folder on the FS & feed our arrays
  500.         ///////////////////////////////////////////////////
  501.         if (opendir($sFolderPath) !== false)
  502.         {
  503.             $handle = opendir($sFolderPath);
  504.         }
  505.         else
  506.         {
  507.             $arFolder[$cFiles][0] = "badperms";
  508.             $arFolder[$cFiles][1] = "3"; // per (file types) legend 3 = error
  509.         }
  510.  
  511.         while (false !== ($file = readdir($handle)))
  512.         {
  513.             $sFullPath = $sFolderPath . "\\" . $file;
  514.             // we've got a directory, make sure it's not the . or .. folder and stuff it's info in the folder array
  515.             if ($nmSharedPlace->IsDisplayableItem($sFullPath) && is_dir($sFullPath) && ($file != ".") && ($file != ".."))
  516.             {
  517.                 $arFolder[$cFiles][0] = $file;
  518.                 $arFolder[$cFiles][1] = "0"; // per (file types) legend 0 = folder
  519.             }
  520.             // we've got a file, let's grab the extension and stuff it's info in either the photo or the non photo array
  521.             if (is_file($sFullPath) && is_readable($sFullPath) && $nmSharedPlace->IsDisplayableItem($sFullPath))
  522.             {
  523.                 $sFullFilePath = $sFolderPath . "\\" . $file;
  524.                 $fileExtension = strtolower(strrchr($file, "."));
  525.                 switch ($fileExtension)
  526.                 {
  527.                     case ".n2g":
  528.                         // our special little files, let's not show them...
  529.                         // TODO - make them system files when saving??
  530.                         break;
  531.                     case ".mp3":
  532.                     case ".wma":
  533.                         $bPlaylistLinkEnabled = true;
  534.                         $arFilesFiles[$cFiles][0] = urlEncodeString($file);
  535.                         $arFilesFiles[$cFiles][1] = "2"; // per (file types) legend 2 = non photo file
  536.                         break;
  537.                     case ".jpg":
  538.                     case ".jpe":
  539.                     case ".jpeg":
  540.                     case ".jfif":
  541.                     case ".gif":
  542.                     case ".png":
  543.                         $bSlideShowLinkEnabled = true; // we've got at least one slideshow capable file, let's display the link
  544.                         $arFilesPhotos[$cFiles][0] = urlEncodeString($file);
  545.                         $arFilesPhotos[$cFiles][1] = "1"; // per (file types) legend 1 = photo file
  546.                         break;
  547.                     case ".bmp":
  548.                     case ".dib":
  549.                     case ".ico":
  550.                     case ".tif":
  551.                     case ".tiff":
  552.                         $arFilesPhotos[$cFiles][0] = urlEncodeString($file);
  553.                         $arFilesPhotos[$cFiles][1] = "1"; // per (file types) legend 1 = photo file
  554.                         break;
  555.                     default:
  556.                         $arFilesFiles[$cFiles][0] = urlEncodeString($file);
  557.                         $arFilesFiles[$cFiles][1] = "2"; // per (file types) legend 2 = non photo file
  558.                 }
  559.             }
  560.             $cFiles++; // increment the array position counter
  561.         }
  562.     
  563.         ///////////////////////////////////////////////////
  564.         // Let's create the final folder/file array list in this order:
  565.         // 1) folder array if it exists
  566.         // 2) photo files array if it exists
  567.         // 3) non photot files array if it exists
  568.         // NOTE: we prepend these to each other in reverse order
  569.         ///////////////////////////////////////////////////
  570.  
  571.         if (isset($arFilesPhotos) && isset($arFilesFiles))
  572.         {
  573.             $arFilesFiles = returnNatsortedArrayOnIndex($arFilesFiles,0);
  574.             $arFilesPhotos = returnNatsortedArrayOnIndex($arFilesPhotos,0);
  575.             $arFiles = $arFilesPhotos + $arFilesFiles;  
  576.         }
  577.         else
  578.         {
  579.             if (!isset($arFilesPhotos))
  580.             {
  581.                 $arFilesFiles = returnNatsortedArrayOnIndex($arFilesFiles,0);
  582.                 $arFiles = $arFilesFiles;  
  583.             }
  584.             else
  585.             {
  586.                 $arFilesPhotos = returnNatsortedArrayOnIndex($arFilesPhotos,0);            
  587.                 $arFiles = $arFilesPhotos;
  588.             }
  589.         }
  590.         if (isset($arFolder) && isset($arFiles))
  591.         {
  592.             $arFolder = returnNatsortedArrayOnIndex($arFolder,0);
  593.             $arFiles = $arFolder + $arFiles;
  594.         }
  595.         else
  596.         {
  597.             if (!isset($arFiles))
  598.             {
  599.                 $arFolder = returnNatsortedArrayOnIndex($arFolder,0);
  600.                 $arFiles = $arFolder;
  601.             }
  602.         }
  603.         
  604.         ///////////////////////////////////////////////////
  605.         // stuff now defined variables into the arrays
  606.         ///////////////////////////////////////////////////
  607.         $arSharePath[3] = $bSlideShowLinkEnabled;
  608.         $arSharePath[4] = returnPageNumber(count($arFiles),$ObjectsPerPage, $sgPage);  // the page number
  609.         $arSharePath[5] = $bPlaylistLinkEnabled;
  610.         
  611.         ///////////////////////////////////////////////////
  612.         // stuff the arrays in the session for reuse while paging through the folder
  613.         ///////////////////////////////////////////////////
  614.         $_SESSION['currentFolderFiles'] = $arFiles;
  615.         $_SESSION['currentFolderInfo'] = $arSharePath;
  616.     }
  617.     $arSharePath = $_SESSION['currentFolderInfo'];
  618.     $arFiles = $_SESSION['currentFolderFiles'];
  619. }
  620.  
  621. function getFolderName($nmSharedPlace, $sPath)
  622. {
  623.     // normally we could just do a basename on the path to get the folder name
  624.     // however, when the folder name is the share name, it is not the friendly share name
  625.     $sShareName  = getShareTitle ($nmSharedPlace);
  626.     if (isset($sShareName) && (("\\" . basename($sPath)) == strrchr($nmSharedPlace->Unc, "\\")))
  627.     {
  628.         $sFolderName = $sShareName;
  629.     }
  630.     else
  631.     {
  632.         $sFolderName = basename($sPath);
  633.     }
  634.     $iUncLocationLength = strlen($nmSharedPlace->Location);
  635.     if ($sFolderName == substr(stripslashes($nmSharedPlace->Unc), $iUncLocationLength + 1))
  636.     {
  637.         // we've got the truncated share name here (os level one), let's get a better name for it
  638.         $sFolderName = $nmSharedPlace->ShareName;
  639.     }
  640.     return $sFolderName;
  641. }
  642.  
  643. function getShareTitle ($nmSharedPlace)
  644. {
  645.     $sShareName     = $nmSharedPlace->ShareName;
  646.     $sFriendlyName  = $nmSharedPlace->FriendlyName;
  647.     $sAccessLevel   = $nmSharedPlace->AccessLevel;
  648.     
  649.     if (isValidString($sFriendlyName) && $sAccessLevel ==  0)
  650.     {
  651.         return $sFriendlyName;
  652.     }
  653.     else
  654.     {
  655.         return $sShareName;
  656.     }
  657. }
  658.  
  659. function isSupportedDownloadExtension($sDownloadUnsupportedExtensions, $sFileExtension)
  660. {
  661.     if (isValidString($sFileExtension))
  662.     {
  663.         if (strpos($sDownloadUnsupportedExtensions, strtolower($sFileExtension)) === false)
  664.         {
  665.             return true;
  666.         }
  667.         else
  668.         {
  669.             return false;
  670.         }
  671.     }
  672. }
  673.  
  674. function returnNatsortedArrayOnIndex( &$arArray, $index = null, $bCaseInsensitive = true )
  675. {
  676.     // init array vars needed
  677.     $arTemp = array();
  678.     $arReturn = array();
  679.     // create a temp array with the key to be natsorted
  680.     foreach ( $arArray as $key=>$value ) 
  681.     {
  682.         reset($value);
  683.         $arTemp[$key] = is_null($index)
  684.             ? current($value)
  685.             : $value[$index];
  686.     }
  687.     // natcasesort the temp array on the desired key now stored in it
  688.     if ($bCaseInsensitive)
  689.     {
  690.         natcasesort($arTemp);
  691.     }
  692.     else
  693.     {
  694.         natsort($arTemp);
  695.     }
  696.     
  697.     // create a return array that matches the key order of the input array, but sorted as per teh temp array
  698.     foreach ( $arTemp as $key=>$value ) 
  699.     {
  700.         $arReturn[$key] = $arArray[$key];
  701.     }
  702.     // return the array
  703.     return $arReturn;
  704. }
  705. ?>